package cn.gwm.flink.streaming.dwm.charge.bussiness;

import cn.gwm.flink.streaming.config.ChargeConfigEnum;
import cn.gwm.flink.streaming.constant.BaseFields;
import cn.gwm.flink.streaming.constant.VehicleType;
import cn.gwm.flink.streaming.dwm.charge.bean.ChargeArgs;
import cn.gwm.flink.streaming.dwm.charge.bean.ChargeFavourable;
import cn.gwm.flink.streaming.dwm.charge.facory.ChargeStateFactory;
import cn.gwm.flink.streaming.dwm.charge.model.ChargeConstant;
import cn.gwm.flink.streaming.dwm.charge.model.ChargeModelEnum;
import cn.gwm.flink.streaming.dwm.charge.model.ChargeStateEnum;
import cn.gwm.flink.streaming.dwm.charge.support.ChargeFieldSupport;
import cn.gwm.flink.streaming.dwm.charge.support.ChargeState;
import cn.gwm.flink.streaming.dwm.charge.support.ChargeStateSupport;
import cn.gwm.flink.streaming.dwm.charge.template.ChargeStateModel;
import cn.gwm.flink.streaming.dws.reservecharge.enums.ChargeConnectTypeEnum;
import cn.gwm.utils.ConfigLoader;
import cn.gwm.utils.DistanceUtils;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.flink.api.common.state.MapState;
import org.apache.flink.api.common.state.ValueState;
import org.apache.flink.util.Collector;

import java.util.Arrays;
import java.util.List;

import static cn.gwm.flink.streaming.dwm.charge.support.ChargeFieldSupport.setChargeType;

/**
 * @ClassName ChargeHandle
 * @Description 充电稳态及波动相关功能处理
 * @Author LiangGuang
 * @Date 2023/05/10 13:44
 */
@Slf4j
public class ChargeHandle {
    /**
     * 距离偏差
     */
    private static Double DISTANCE_DEVIATION = new Double(100);

    /**
     * 休眠时长判断
     */
    public static final Integer DORMANCY_TIMEDORMANCY_TIME = ConfigLoader.getInt("data.dormancy.time");

    public static void charge(ValueState<JSONObject> preDataState,
                              ValueState<ChargeStateEnum> steadyState,
                              MapState<String, List> mapState,
                              ChargeStateEnum chargeState,
                              ChargeArgs args) throws Exception {
        // 经纬度的监听 --> 如果 两点距离 100米内,则默认同一位置
        canGpsHandle(args);
        chargeModelHandle(args);
        // 对 优惠充电字段进行判断
        favourableCharge(args);
        Boolean switchGun = switchGun(preDataState, steadyState, mapState, args);
        dormancyCheck(switchGun, preDataState, steadyState, chargeState, mapState, args);
        steadyHandle(preDataState, steadyState, mapState, chargeState, args);
    }

    public static void canGpsHandle(ChargeArgs args) throws Exception {
        JSONObject summar = args.getSummarState().value();
        JSONObject nowData = args.getRealNowData();
        JSONObject bandSummar = args.getBandSummarState().value();
        if (summar != null) {
            if (!summar.containsKey("gpsAoi") || !summar.getBool("gpsAoi")) {
                if (!BaseFields.defaultVal.equals(nowData.getStr(BaseFields.LATITUDE))
                        && !BaseFields.defaultVal.equals(nowData.getStr(BaseFields.LONGITUDE))) {
                    if (summar.containsKey("gpsAoi")) {
                        double distance = DistanceUtils.distance(summar.getDouble(BaseFields.LONGITUDE), summar.getDouble(BaseFields.LATITUDE),
                                nowData.getDouble(BaseFields.LONGITUDE), nowData.getDouble(BaseFields.LATITUDE));
                        if (distance <= DISTANCE_DEVIATION) {
                            summar.set("gpsAoi", true);
                        } else {
                            // 用当前 经纬度
                            ChargeFieldSupport.summmarAoi(summar, nowData.getStr(BaseFields.LATITUDE), nowData.getStr(BaseFields.LONGITUDE));
                            summar.set(BaseFields.LONGITUDE, nowData.getStr(BaseFields.LONGITUDE));
                            summar.set(BaseFields.LATITUDE, nowData.getStr(BaseFields.LATITUDE));
                            bandSummar.set(BaseFields.LONGITUDE, nowData.getStr(BaseFields.LONGITUDE));
                            bandSummar.set(BaseFields.LATITUDE, nowData.getStr(BaseFields.LATITUDE));
                            // 更新页面
                            args.getOut().collect(bandSummar);
                        }
                    } else {
                        // 用当前 经纬度
                        ChargeFieldSupport.summmarAoi(summar, nowData.getStr(BaseFields.LATITUDE), nowData.getStr(BaseFields.LONGITUDE));
                        summar.set(BaseFields.LONGITUDE, nowData.getStr(BaseFields.LONGITUDE));
                        summar.set(BaseFields.LATITUDE, nowData.getStr(BaseFields.LATITUDE));
                        bandSummar.set(BaseFields.LONGITUDE, nowData.getStr(BaseFields.LONGITUDE));
                        bandSummar.set(BaseFields.LATITUDE, nowData.getStr(BaseFields.LATITUDE));
                        // 更新页面
                        args.getOut().collect(bandSummar);
                    }
                }
                args.getSummarState().update(summar);
                args.getBandSummarState().update(bandSummar);
            }
        }
    }


    /**
     * 充电模式的判断
     */
    public static void chargeModelHandle(ChargeArgs args) throws Exception {
        JSONObject nowData = args.getRealNowData();
        ChargeConstant constant = args.getConstant();
        if (!BaseFields.defaultVal.equals(nowData.getStr(constant.getPlugChrgnMode()))) {
            JSONObject summar = args.getSummarState().value();
            JSONObject bandSummar = args.getBandSummarState().value();
            if (summar != null) {
                String chargeModel = bandSummar.getStr("chargeModel");
                // 已经多模式就不用判断了
                if (!ChargeModelEnum.CHARGE_MULTIMODE.getCode().equals(chargeModel)) {
                    ChargeStateEnum chargeState = args.getNowState();
                    MapState<String, JSONObject> modelFirstState = args.getChargeModelFirstState();
                    if (ChargeStateEnum.END.equals(chargeState) || ChargeStateEnum.FULLY.equals(chargeState)) {
                        return;
                    }
                    Collector<JSONObject> out = args.getOut();
                    String nowChargeModel = ChargeFieldSupport.chargeModel(nowData, constant);
                    if (!chargeModel.equals(nowChargeModel)) {
                        // bandSummar 为当前模式
                        bandSummar.set("chargeModel", nowChargeModel);
                        bandSummar.set("Tbox_BattSOCLim", nowData.get(constant.getTboxBattSoc()));
                        summar.set("Tbox_BattSOCLim", nowData.get(constant.getTboxBattSoc()));
                        modelFirstState.clear();
                        modelFirstState.put(nowChargeModel, nowData);
                        out.collect(bandSummar);
                    } else {
                        if (modelFirstState.contains(nowChargeModel)) {
                            JSONObject chargeNow = modelFirstState.get(nowChargeModel);
                            if ((nowData.getLong(BaseFields.tid) - chargeNow.getLong(BaseFields.tid)) >= 10 * 60 * 1000L) {
                                if (summar.getBool("chargeModelFlag")) {
                                    summar.set("chargeModel", ChargeModelEnum.CHARGE_MULTIMODE.getCode());
                                    bandSummar.set("chargeModel", ChargeModelEnum.CHARGE_MULTIMODE.getCode());

                                    bandSummar.set("Tbox_BattSOCLim", nowData.get(constant.getTboxBattSoc()));
                                    summar.set("Tbox_BattSOCLim", nowData.get(constant.getTboxBattSoc()));

                                    out.collect(bandSummar);
                                } else {
                                    summar.set("chargeModelFlag", true);
                                    summar.set("chargeModel", bandSummar.getStr("chargeModel"));
                                }
                                modelFirstState.clear();
                            }
                        }
                    }
                    args.getBandSummarState().update(bandSummar);
                    args.getSummarState().update(summar);
                }
            }
        }
    }


    public static void favourableCharge(ChargeArgs args) throws Exception {
        // 来了优惠信息 就 下发，累计下发，
        JSONObject nowData = args.getRealNowData();
        ChargeConstant constant = args.getConstant();
        MapState<Long, ChargeFavourable> mapState = args.getFavourableMapState();
        if (!BaseFields.defaultVal.equals(nowData.getStr(constant.getRequestTime()))) {
            if (!mapState.contains(nowData.getLong(constant.getRequestTime()))) {
                // 新的 优惠信息来了
                // 累加之前的，合并到 bandsummar 上 下发出去
                JSONObject bandSummar = args.getBandSummarState().value();
                JSONObject summar = args.getSummarState().value();
                ChargeFavourable favourable = new ChargeFavourable()
                        .setDiscountPower(ChargeFieldSupport.getIntVal(nowData, constant.getDiscountPower()))
                        .setDiscountTime(ChargeFieldSupport.getIntVal(nowData, constant.getDiscountTime()))
                        .setExpensivePower(ChargeFieldSupport.getIntVal(nowData, constant.getExpensivePower()))
                        .setExpensiveTime(ChargeFieldSupport.getIntVal(nowData, constant.getExpensiveTime()));
                mapState.put(nowData.getLong(constant.getRequestTime()), favourable);
                if (bandSummar == null) {
                    // 此时来了数据，但是  优惠信息也还是空，很奇怪 如果全为空，则不需要存 无意义
                    if (!favourable.isZero()) {
                        JSONObject favourableJson = ChargeStateSupport.createFavourable(nowData, constant, favourable);
                        args.getOut().collect(favourableJson);
                        mapState.clear();
                        mapState.put(nowData.getLong(constant.getRequestTime()), favourable);
                    }
                    return;
                }
                String discountPower = String.format("%.1f", summar.getDouble("discountPower") + favourable.getDiscountPower() * 0.1);
                String expensivePower = String.format("%.1f", summar.getDouble("expensivePower") + favourable.getExpensivePower() * 0.1);
                Integer discountTime = summar.getInt("discountTime") + favourable.getDiscountTime();
                Integer expensiveTime = summar.getInt("expensiveTime") + favourable.getExpensiveTime();

                Double yDiscountPower = bandSummar.getDouble("discountPower") == null ? 0 : bandSummar.getDouble("discountPower");
                Double yExpensivePower = bandSummar.getDouble("expensivePower") == null ? 0 : bandSummar.getDouble("expensivePower");
                Integer yDiscountTime = bandSummar.getInt("discountTime") == null ? 0 : bandSummar.getInt("discountPower");
                Integer yExpensiveTime = bandSummar.getInt("expensiveTime") == null ? 0 : bandSummar.getInt("discountPower");

                summar.set("discountPower", discountPower);
                summar.set("expensivePower", expensivePower);
                summar.set("discountTime", discountTime);
                summar.set("expensiveTime", expensiveTime);
                // 对比时间 -， 是否能匹配上  requestTime 一定大于 当前 item_time   requestTime 一定小于 startChargeTime 且注意 bandSummar 的累加
                Long requestTime = nowData.getLong(constant.getRequestTime());
                if (bandSummar.getLong("startChargeTime") < requestTime) {
                    bandSummar.set("discountPower", String.format("%.1f", yDiscountPower + favourable.getDiscountPower() * 0.1));
                    bandSummar.set("expensivePower", String.format("%.1f", yExpensivePower + favourable.getExpensivePower() * 0.1));
                    bandSummar.set("discountTime", yDiscountTime + favourable.getDiscountTime());
                    bandSummar.set("expensiveTime", yExpensiveTime + favourable.getExpensiveTime());
                } else {
                    // 说明迟到了 [稳态时间长度]  bandSummar 不变，但是 优惠信息要存储
                    JSONObject favourableJson = ChargeStateSupport.createFavourable(nowData, constant, favourable);
                    args.getOut().collect(favourableJson);
                }
                args.getBandSummarState().update(bandSummar);
                args.getSummarState().update(summar);
            }
        }

    }

    /**
     * 切换枪的判断和处理
     *
     * @param preDataState
     * @param steadyState
     * @param mapState
     * @param args
     * @throws Exception
     */
    public static Boolean switchGun(ValueState<JSONObject> preDataState, ValueState<ChargeStateEnum> steadyState,
                                    MapState<String, List> mapState, ChargeArgs args) throws Exception {
        JSONObject prevData = preDataState.value();
        if (prevData == null) {
            return false;
        }
        JSONObject nowData = args.getRealNowData();
        ChargeStateEnum steady = steadyState.value();
        Boolean changeCharging = changeCharging(args.getConstant(), args.getSummarState().value(), nowData);
        if (changeCharging) {
            // 中断且切枪，则上一次物理充电结束
            args.setFirstData(nowData);
            args.setRealNowData(nowData);
            args.setPrevData(prevData);
            if (steady != null) {
                args.setPrevEndData((JSONObject) mapState.get(steady.getState()).get(0));
            } else {
                args.setPrevEndData(prevData);
            }
            changeChargingHandle(steadyState, mapState, args);
        }
        return changeCharging;
    }

    /**
     * @param switchGun
     * @param preDataState
     * @param steadyState
     * @param chargeState
     * @param mapState
     * @param args
     * @return 是否完整 true 完整 false 不完整，只在生成summar时使用
     * @throws Exception
     */
    public static void dormancyCheck(Boolean switchGun, ValueState<JSONObject> preDataState,
                                     ValueState<ChargeStateEnum> steadyState,
                                     ChargeStateEnum chargeState,
                                     MapState<String, List> mapState,
                                     ChargeArgs args) throws Exception {
        JSONObject prevData = preDataState.value();
        if (prevData == null) {
            return;
        }
        JSONObject nowData = args.getRealNowData();
        // 两条数据相差规定的休眠时间，则需要进行处理
        if (nowData.getLong(BaseFields.tid) - prevData.getLong(BaseFields.tid) >= DORMANCY_TIMEDORMANCY_TIME * 1000L) {
            ChargeStateEnum steady = steadyState.value();
            if (!switchGun) {
                if (steady != null && !ChargeStateEnum.END.equals(steady)) {
                    // 休眠还是缺失数据的判断   是否休眠
                    Boolean dormancyFlag = Boolean.TRUE;
                    if (args.getSummarState().value() != null) {
                        // 如果当前状态是 拔枪，则不需要进行吧
                        JSONObject summar = args.getSummarState().value();
                        dormancyFlag = ChargeFieldSupport.setComplete(summar, prevData, dormancyFlag, args);
                    }
                    // 当前稳态的最后一条数据
                    List<JSONObject> list = mapState.get(steady.getState());
                    JSONObject endData = list.get(0);
                    if (endData.getLong(BaseFields.tid) == prevData.getLong(BaseFields.tid)) {
                        // 属于突然没有数据，中断或者休眠，一段时间后来了数据
                        ChargeStateModel stateHandle;
                        if (ChargeStateEnum.CHARGING.equals(steady) && dormancyFlag) {
                            // 结束充电
                            stateHandle = ChargeStateFactory.getStateHandle(ChargeStateEnum.CHARGING);
                            args.setPrevData(endData);
                            args.setPrevEndData(endData);
                            stateHandle.stateEnd(args);
                            args.getChargeBreakState().update(endData.getLong(BaseFields.tid));
                            if (ChargeStateEnum.CHARGING.equals(chargeState)) {
                                // 恰巧新来的也是 充电，则直接开启 主要是为了延续
                                args.setFirstData(nowData);
                                args.setNowState(ChargeStateEnum.CHARGING);
                                stateHandle.stateStart(args);
                                mapState.clear();
                                steadyState.update(ChargeStateEnum.CHARGING);
                            } else {
                                mapState.remove(ChargeStateEnum.CHARGING.getState());
                                steadyState.update(ChargeStateEnum.UNKNOWN);
                                mapState.put(ChargeStateEnum.UNKNOWN.getState(), Arrays.asList(prevData));
                            }
                        }
                    } else {
                        // 缺失数据之前，已经有状态变化了
                        // 在中断前已经出现了波动状态
                        if (ChargeStateEnum.CHARGING.equals(steady)) {
                            // 结束 充电 其他状态交给稳态处理
                            args.setPrevEndData(endData);
                            ChargeStateModel stateHandle = ChargeStateFactory.getStateHandle(steady);
                            stateHandle.stateEnd(args);
                            mapState.remove(ChargeStateEnum.CHARGING.getState());
                            if (dormancyFlag) {
                                args.getChargeBreakState().update(prevData.getLong(BaseFields.tid));
                            }
                            steadyState.update(ChargeStateEnum.UNKNOWN);
                            mapState.put(ChargeStateEnum.UNKNOWN.getState(), Arrays.asList(prevData));
                        }
                        // 中断前如果出现这个，则直接去掉，因为 中断了  --> 是否补充波动中的那一小段，再说
                        if (mapState.contains(ChargeStateEnum.CHARGING.getState())) {
                            mapState.remove(ChargeStateEnum.CHARGING.getState());
                        }
                    }
                } else {
                    // 判断 mapstate中是否有充电，且上一条也是充电，  这里也可以直接将 中断前的去掉，从当前开始
                    if (mapState.contains(ChargeStateEnum.CHARGING.getState()) && ChargeStateEnum.CHARGING.equals(chargeState)) {

                        // 那么，需要判断 上一条是否也是充电，如果是，则结束之前的稳态，并生成 波动中的充电阶段，本次为新的
                        ChargeStateEnum preState = ChargeState.realState(args.getConstant(), prevData, args.getSummarState());
                        if (ChargeStateEnum.CHARGING.equals(preState)) {
                            ChargeConstant constant = args.getConstant();
                            Double nowBmsSoc = nowData.getDouble(constant.getBmsInnerSOC());
                            Double preBmsSoc = prevData.getDouble(constant.getBmsInnerSOC());
                            if (Math.abs(nowBmsSoc - preBmsSoc) < 0.5d) {
                                List<JSONObject> chargingList = mapState.get(ChargeStateEnum.CHARGING.getState());
                                ChargeStateModel stateHandle = ChargeStateFactory.getStateHandle(ChargeStateEnum.CHARGING);
                                args.setFirstData(chargingList.get(1));
                                args.setNowState(ChargeStateEnum.CHARGING);
                                stateHandle.stateStart(args);
                                // 充电结束
                                args.setPrevEndData(prevData);
                                stateHandle.stateEnd(args);
                                // 设置
                                mapState.clear();
                                steadyState.update(ChargeStateEnum.UNKNOWN);
                                mapState.put(ChargeStateEnum.UNKNOWN.getState(), Arrays.asList(prevData));
                            } else {
                                // 缺数据，不需要管
                                // 如何设置此时已经非完整了呢 --> 还没有记录  但是应该告诉记录生成时直接赋值不完整 由于 这里超过5分钟，所以一定得生成记录了
                                args.setIsComplete(0);
                            }
                        } else {
                            mapState.remove(ChargeStateEnum.CHARGING.getState());
                        }
                    }
                }
            }
        }
    }


    public static void steadyHandle(ValueState<JSONObject> preDataState, ValueState<ChargeStateEnum> steadyState,
                                    MapState<String, List> mapState, ChargeStateEnum nowState, ChargeArgs args) throws Exception {
        JSONObject prevData = preDataState.value();
        JSONObject nowData = args.getRealNowData();
        ChargeStateEnum steady = steadyState.value();

        if (nowState.equals(steady)) {
            if (ChargeStateEnum.CHARGING.equals(nowState)) {
                // 是否 改变充电类型
                JSONObject summar = args.getSummarState().value();
                JSONObject bandSummar = args.getBandSummarState().value();
                setChargeType(args.getConstant(), args.getRealNowData(), summar);
                // 如果 bandSummar和 summar的充电类型不一致,修改 banSummar 并发送出去
                if (!summar.getStr("chargeType").equals(bandSummar.getStr("chargeType"))) {
                    bandSummar.set("chargeType", summar.getStr("chargeType"));
                    args.getOut().collect(bandSummar);
                    args.getBandSummarState().update(bandSummar);
                    args.getSummarState().update(summar);
                }
                // 明细 发送出去
                args.getOut().collect(ChargeStateSupport.createDetail(args, nowData));
            }
            mapState.clear();
            mapState.put(nowState.getState(), Arrays.asList(nowData));
        } else {
            List<JSONObject> list = mapState.get(nowState.getState());
            if (list == null) {
                List<JSONObject> cacheData = CollectionUtil.newArrayList();
                cacheData.add(prevData);
                cacheData.add(nowData);
                mapState.put(nowState.getState(), cacheData);
                //  充电中，则 缓存 数据
                if (ChargeStateEnum.CHARGING.equals(nowState)) {
                    args.getListState().add(nowData);
                }
            } else {
                List<JSONObject> cacheData = mapState.get(nowState.getState());
                // 当前波动的 首条记录
                JSONObject firstData = cacheData.get(1);
                Long happenedTid = firstData.getLong(BaseFields.tid);
                Long nowTid = nowData.getLong(BaseFields.tid);
                Long waveTime = Integer.valueOf(ChargeConfigEnum.DATAPERSISTENCE.getValue()) * 1000L;
                if (VehicleType.ES11.equals(nowData.getStr(VehicleType.VEHICLE_TYPE))) {
                    waveTime = 60 * 1000L;
                }
                if (ChargeStateEnum.END.equals(nowState)) {
                    waveTime = Integer.valueOf(ChargeConfigEnum.PLUGINTERVAL.getValue()) * 60 * 1000L;
                }
                if (ChargeStateEnum.CHARGING.equals(nowState)) {
                    args.getListState().add(nowData);
                }
                if ((nowTid - happenedTid) >= waveTime) {
                    // 1. 结束当前 稳态 3. 开启新的稳态
                    ChargeStateModel stateHandle;
                    if (steady != null && !ChargeStateEnum.END.equals(steady)) {
                        stateHandle = ChargeStateFactory.getStateHandle(steady);
                        args.setPrevEndData((JSONObject) mapState.get(steady.getState()).get(0));
                        stateHandle.stateEnd(args);
                    }
                    stateHandle = ChargeStateFactory.getStateHandle(nowState);
                    if (ChargeStateEnum.END.equals(nowState)) {
                        args.setPrevData((JSONObject) mapState.get(nowState.getState()).get(0));
                        args.setFirstData((JSONObject) mapState.get(nowState.getState()).get(1));
                    } else {
                        args.setFirstData(firstData);
                        args.setNowState(nowState);
                    }
                    stateHandle.stateStart(args);
                    steadyState.update(nowState);
                    mapState.clear();
                    mapState.put(nowState.getState(), Arrays.asList(nowData));
                }
            }
        }
    }


    /**
     * 是否进行了快慢枪的切换
     *
     * @param constant
     * @param summar
     * @param nowData
     * @return
     */
    public static Boolean changeCharging(ChargeConstant constant, JSONObject summar, JSONObject nowData) {
        // 快充状态
        if (summar != null) {
            ChargeConnectTypeEnum connectType = ChargeState.connectType(constant, nowData);
            // kc==1 快充 kc==0 慢充
            Integer kc = summar.getInt("BMS_DCChrgConnect");
            if (kc == 1 && connectType.equals(ChargeConnectTypeEnum.SLOW)) {
                return true;
            }
            if (kc == 0 && connectType.equals(ChargeConnectTypeEnum.QUICK)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 发生快慢充切换时，结束上一次充电[物理]
     *
     * @param steadyState
     * @param mapState
     * @param args
     * @throws Exception
     */
    public static void changeChargingHandle(ValueState<ChargeStateEnum> steadyState, MapState<String, List> mapState, ChargeArgs args) throws Exception {

        // 1. 结束稳态中的充电状态 2. 结束物理充电 3.连接时间直接赋值当前条时间即可。稳态在前置判断时已完成校验
        ChargeStateModel stateHandle = ChargeStateFactory.getStateHandle(steadyState.value());
        stateHandle.stateEnd(args);
        stateHandle = ChargeStateFactory.getStateHandle(ChargeStateEnum.END);
        if (mapState.contains(ChargeStateEnum.END.getState())) {
            args.setPrevData((JSONObject) mapState.get(ChargeStateEnum.END.getState()).get(0));
        }
        stateHandle.stateStart(args);
        mapState.clear();
        mapState.put(ChargeStateEnum.END.getState(), Arrays.asList(args.getPrevData()));
        steadyState.update(ChargeStateEnum.END);

        // 此处 应给新的状态波动
        ChargeStateEnum nowState = args.getNowState();
        List<JSONObject> cacheData = CollectionUtil.newArrayList();
        cacheData.add(args.getPrevData());
        cacheData.add(args.getFirstData());
        args.setIsComplete(1);
        if (ChargeStateEnum.SUSPEND.equals(nowState)) {
            nowState = ChargeStateEnum.WAIT;
        }
        mapState.put(nowState.getState(), cacheData);
        args.getConnectTimeState().update(args.getFirstData().getLong(BaseFields.tid));
    }

}
